package com.usaas.search.controller.admin;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.usaas.common.core.controller.BaseController;
import com.usaas.common.core.domain.AjaxResult;
import com.usaas.common.enums.BusinessType;
import com.usaas.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.usaas.common.annotation.Log;
import com.usaas.search.dto.PlatUserDto;
import com.usaas.search.service.IPlatUserService;
/**
 * 系统用户Controller
 *
 * @author Helios
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/admin/search/platUser")
public class AdminPlatUserController extends BaseController {

    @Autowired
    private IPlatUserService platUserService;

    /**
     * 查询系统用户列表
     */
    @PreAuthorize("@ss.hasPermi('search:platUser:list')")
    @Log(title = "管理端系统用户list查询", businessType = BusinessType.OTHER)
    @PostMapping("/list")
    public AjaxResult list(@RequestBody PlatUserDto platUserDto) {
        List<PlatUserDto> list = platUserService.queryList(platUserDto);
        return AjaxResult.success(list);
    }


    /**
     * 查询系统用户分页列表
     */
    @PreAuthorize("@ss.hasPermi('search:platUser:list')")
    @Log(title = "管理端系统用户page查询", businessType = BusinessType.OTHER)
    @PostMapping("/page")
    public AjaxResult page(@RequestBody PlatUserDto platUserDto) {
        return platUserService.queryPage(platUserDto);
    }


    /**
     * 导出系统用户列表
     */
    @PreAuthorize("@ss.hasPermi('search:platUser:export')")
    @Log(title = "管理端导出系统用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,PlatUserDto platUserDto) {
        List<PlatUserDto> list = platUserService.queryList(platUserDto);
        ExcelUtil<PlatUserDto> util = new ExcelUtil<>(PlatUserDto.class);
        util.exportExcel(response, list, "系统用户数据");
    }

    /**
     * 获取系统用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('search:platUser:query')")
    @Log(title = "管理端获取系统用户详情查询", businessType = BusinessType.OTHER)
    @PostMapping(value = "/getInfo")
    public AjaxResult getInfo(@RequestBody PlatUserDto platUserDto) {
        return AjaxResult.success(platUserService.queryById(platUserDto.getId()));
    }

    /**
     * 新增系统用户
     */
    @PreAuthorize("@ss.hasPermi('search:platUser:add')")
    @Log(title = "管理端新增系统用户", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody PlatUserDto platUserDto) {
        return toAjax(platUserService.add(platUserDto));
    }

    /**
     * 修改系统用户
     */
    @PreAuthorize("@ss.hasPermi('search:platUser:edit')")
    @Log(title = "管理端修改系统用户", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResult edit(@RequestBody PlatUserDto platUserDto) {
        return toAjax(platUserService.update(platUserDto));
    }

    /**
     * 删除系统用户
     */
    @PreAuthorize("@ss.hasPermi('search:platUser:remove')")
    @Log(title = "管理端删除系统用户", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public AjaxResult del(@RequestBody PlatUserDto platUserDto) {
        return toAjax(platUserService.removeBatch(platUserDto.getIds()));
    }

}
